<template>
  <view>
	  <view v-for="item in goodsList" :key="item.goods_id" @click="goToGoodsDetail(item)">
	  <my-goods :goods="item"></my-goods>
	  </view>
  </view>
</template>

<script>
	export default {
		data() {
			return {
				query:'',
				pagenum:1,
				goodsList:[],
				total:0,
				isLoading:false,
			};
		},
		methods:{
				goBack(){
					uni.navigateBack()
				},
				async getGoodsList(){
					this.isLoading = true
					if(this.total >= this.pagenum*20 || this.total === 0){
					const {data:message} = await uni.$http.get('/api/public/v1/goods/search',{
						query:this.query,
						pagenum:this.pagenum,
						pagesize:20
					})
					console.log(message)
					if(message.meta.status !== 200) return uni.$showMsg()
					this.total = message.message.total
					this.pagenum++
					this.goodsList.push(...message.message.goods)
					}else uni.$showMsg('暂无数据')
					console.log(this.goodsList)
					this.isLoading = false
				},
				goToGoodsDetail(item){
					uni.navigateTo({
						url:'/subpkg/goods_detail/goods_detail?id=' + item.goods_id
					})
				}
				
		},
		onLoad(options) {
			this.query = options.query
			this.getGoodsList()
			console.log(this.goodsList)
		},
		onReachBottom() {
			if(this.isLoading) return
			this.getGoodsList()
			console.log('the Loading')
		},
		onPullDownRefresh() {
			this.pagenum = 1
			this.goodsList = []
			this.getGoodsList()
			uni.stopPullDownRefresh()
		}
	}
</script>

<style lang="scss">

</style>
